/********************************************
 * Joe Helgeson
 * CS362 Assignment 4
 * randomtestcard.c - tests smithy
 * (adds +3 cards to hand)
 *******************************************/

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

//enabling debugging messages to appear
//#ifdef DEBUG
//#undef DEBUG
//#endif
//#define DEBUG 1

void testIt(struct gameState* tState);

///////////////////////////////////////
int main(int argc, char const** argv) {
	struct gameState* tState = malloc(sizeof(struct gameState));
	testIt(tState);
	free(tState);
	return 0;
}

///////////////////////////////////////
void testIt(struct gameState* tState) {

/* personal notes (ignore): 
 int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, struct gameState *state)
 int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
*/

	//general initial game setup
	srand(time(NULL));
	int numPlayers = 2;
	int kingdomCards[10];
	int i;
	for (i=0; i<10; i++){
		kingdomCards[i] = i+10;		//offset by 10 to be sure smithy is covered in kingdom cards in play
	}
	int randomSeed = rand() % 100; //arbitrary number for various functions (usually set by user on cmd line with playdom)
	
	//initialize game
	int res1 = initializeGame(numPlayers, kingdomCards, randomSeed, tState);
	assert(res1 == 0);

	//specific setup for card under test
	int handPos = 0;
	int card = smithy;
	int origHandSize = 0;
	int choice1 = 0; //irrelevant for this card
	int choice2 = 0; //irrelevant for this card
	int choice3 = 0; //irrelevant for this card
	int bonusval = 0; //irrelevant for this card
	int* bonus = &bonusval; //irrelevant for this card

	int t;
	for (t=0; t<50; t++) {
		//randomly set a hand size and save a backup
		origHandSize = rand() % 10 + 1; //need at least 1 card to play
		tState->handCount[0] = origHandSize;  //backup hand count of player 0 to compare against

		printf("For %d card hand, ", origHandSize);

		//test card #13 (smithy)
		res1 = cardEffect(card, choice1, choice2, choice3, tState, handPos, bonus);
		assert(res1 == 0);

		//post-play tests
		//check that player's hand size is +2 (= +3 minus smithy card discarded)
		if (tState->handCount[0] == origHandSize + 2) {
			printf("Test passed, Smithy netted +2 cards (new hand size = %d)\n", tState->handCount[0]);
		}
		else {
			printf("Test failed, (new hand size = %d)\n", tState->handCount[0]);
			return;
		}
	}
	printf("Smithy unit test passed.\n");
	return;
}

